<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>报关单登记系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
	#tablelist{
		min-width:30%;
	}
</style>
<script type="text/javascript">
	$(function() {
        $("#fm_dept").validationEngine();
	});
</script>	
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),0,15) then call JumpErrorPage(2)
id=saferequest("id",1)
if id="" then id=0 else id=cint(id)
submit=saferequest("submit",0)
if id<>0 then
	sql = "select * from dept where id="&id
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sql,conn,1,1
	if not rs.eof then
		dept=rs("dept")
	end if
	rs.close
	set rs=nothing
end if
if submit<>"" then
    ic_code=saferequest("ic_code",0)
	dept=saferequest("dept",0)
    ic_codes=split(ic_code,",")
    if dept="" then call JumpErrorPage(4)
    call ExecuteCommand("delete * from deptic where deptid="&id,false)
	if submit="新增" then
        sql="insert into dept(dept) values('"&dept&"')"
        id=ExecuteCommand(sql,True)
    end if

    for i=0 to Ubound(ic_codes)
        sql_addic="insert into deptic(deptid,icid) values("&id&","&ic_codes(i)&")"
        call ExecuteCommand(sql_addic,false)
    next
	if submit="保存" then call ExecuteCommand("update dept set dept='"&dept&"' where id="&id,false)
    if submit="新增" then response.redirect("dept.asp?id="&cint(id))
end if
%>

<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="fm_dept" name="fm_dept" method="post" class="yform" role="application">
                <div class="subcolumns">
                    <div class="c50l">
                        <div class="type-text">
                            <label for="dept">组名*</label>
                            <input name="dept" id="dept" type="text" size="10" class="validate[required]" value="<%if submit="新增" then response.write("") else response.write(dept)%>" />
                        </div>
                    </div>
                    <div class="c50r">
                        <fieldset>
                            <legend>关联报关IC卡</legend>

                            <%
                                sql_ic = "select * from bwtric left join (select * from deptic where deptid="&id&") as ic on ic.icid=bwtric.id"
                                Set rs_ic = Server.CreateObject("ADODB.Recordset")
                                rs_ic.Open sql_ic,conn,1,1
                                do while not rs_ic.eof
                            %>
                            <div class="type-check">
                                <input name="ic_code" type="checkbox" value="<%=rs_ic("id")%>" <%if rs_ic("id")=rs_ic("icid") then%>checked="checked"<%end if%>/>
                                <label for="ic_code"><%=rs_ic("ic_code")%>(<%=rs_ic("ic_name")%>)</label>
                            </div>
                            <%
                                    rs_ic.movenext
                                loop
                                rs_ic.close
                                set rs_ic=nothing
                            %>
                        </fieldset>
                    </div>
                </div>
				<div class="type-button">
				<%
					if id<>0 then
				%>
					<input type="submit" name="submit" class="submit" value="保存" />
				<%
					else
				%>
					<input type="submit" name="submit" class="submit" value="新增" />
				<%
					end if
				%>
				</div>
			</form>
			<table id="tablelist">
				<thead>
					<tr><th colspan="3" scope="col">分组明细</th></tr>
				</thead>
				<tbody>
					<tr>
						<th scope="col">ID</th>
						<th scope="col">组名</th>
						<th scope="col">关联报关卡</th>
					</tr>
					<%
						sql = "select * from dept order by dept"
						Set rs = Server.CreateObject("ADODB.Recordset")
						rs.Open sql,conn,1,1
						do while not rs.eof
					%>
					<tr>
						<th class="sub" scope="row"><a href="dept.asp?id=<%=rs("id")%>"><%=rs("id")%></a></th>
						<td><%=rs("dept")%></td>
						<td>
                        <%
						sql_ic = "select * from deptic,bwtric where deptic.icid=bwtric.id and deptic.deptid="&rs("id")
						Set rs_ic = Server.CreateObject("ADODB.Recordset")
						rs_ic.Open sql_ic,conn,1,1
						do while not rs_ic.eof
                        %>
                        <a href="bwtric.asp?id=<%=rs_ic("icid")%>"><%=rs_ic("ic_code")%></a>(<%=rs_ic("ic_name")%>)<br />
                        <%
							rs_ic.movenext
						loop
						rs_ic.close
						set rs_ic=nothing
                        %>
                        </td>
                        
					</tr>
					<%
						
							rs.movenext
						loop
						rs.close
						set rs=nothing
					
					%>
					
				</tbody>
			</table>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

